<template>
  <div class="pOrder">
    <div class="address" @click="handleEdit">
      <div class="addressLeft">
        <div class="addressLeft-head">
          <p v-text="address.username">冯某</p>
          <span class="phone" v-text="address.tel">159****6447</span>
          <van-tag
            v-if="address.default"
            plain
            :style="{
              width: '30px',
              height: '20px',
              fontSize: '12px',
              paddingLeft: '10px',
              lineHeight: '25px',
            }"
            type="warning"
            >默认</van-tag
          >
        </div>
        <div class="addressLeft-foot">
          <van-icon name="location" size="16" />
          <p v-text="address.address">阿拉德大陆天界神之都根特</p>
        </div>
      </div>
      <div class="addressRight">
        <img class="right" src="../../img/cart/u691.svg" alt="" />
      </div>
    </div>

    <div class="list">
      <van-card
        v-for="item in list"
        :key="item.id"
        :style="{ background: 'white' }"
        :num="item.num"
        :price="(item.price * item.num) | fix"
        desc="50斤"
        :title="item.title"
        :thumb="item.image"
      />
      <div class="listFoot">
        <div class="listLeft">
          <p>商品合计</p>
        </div>
        <div class="listRight">
          <span>￥{{money | fix}}</span>
        </div>
      </div>
    </div>
    <van-submit-bar
      :label="`实付金额:   `"
      :price="money * 100"
      button-text="提交订单"
    >
      <template #button>
        <van-button
          :style="{
            height: '100%',
            width: '120px',
            marginRight: '-16px',
            backgroundColor: '#1abc9c',
          }"
          type="primary"
          @click="onSubmit(list)"
          >提交订单</van-button
        >
      </template>
    </van-submit-bar>
  </div>
</template>

<script>
export default {
  name: 'pOrder',
  data() {
    return {
      list: [],
      money: 0.0,
      address: [],
    }
  },
  created() {
    const data = JSON.parse(localStorage.getItem('cart'))
    const da = data.filter((item) => {
      return item.checked
    })
    this.list = da
    this.money = JSON.parse(localStorage.getItem('money'))

    const address = this.$store.state.address.addressInfo.find(item => {
      return item.checked
    })
    this.address = address
  },
  methods: {
    onSubmit(data) {
      data.forEach((item) => {
        const id = item.id
        this.$store.commit('cart/removeCart', { id })
      })
      this.$store.commit('cart/addOrder', data)
      this.$store.commit('cart/changeOrder')
      this.$router.push('/success')
    },
    handleEdit() {
      this.$router.push('/address')
    },
  },

}
</script>

<style lang="scss" scoped>
.list {
  display: flex;
  flex-direction: column;
  padding-bottom: 50px;
  .listFoot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .listLeft {
      margin-left: 20px;
      color: #333333;
    }
    .listRight {
      color: #999;
      margin-right: 20px;
    }
  }
  .van-card {
    flex: 1;
    margin-top: 1px;
  }
  .listFoot {
    width: 100%;
    height: 40px;
    background: white;
    margin-top: 5px;
  }
}
.pOrder {
  background-color: rgb(249, 249, 249);
  height: 100%;
  overflow: auto;
}
.address {
  width: 375px;
  height: 100px;
  background-color: white;
  margin-top: 10px;
  margin-bottom: 10px;
  display: flex;
  .addressLeft {
    width: 300px;
    .addressLeft-head {
      display: flex;
      font-size: 16px;
      width: 200px;
      align-items: center;
      margin-left: 50px;
      margin-top: 30px;
      justify-content: space-between;
      img {
        height: 5px;
        width: 375px;
      }
      p {
        color: #666;
        margin-right: 10px;
      }
    }
    .addressLeft-foot {
      display: flex;
      align-items: center;
      margin-left: 33px;
      font-size: 14px;
      color: #999;
      i {
        margin-top: 7px;
      }
      p {
        margin-top: 7px;
      }
    }
  }
  .addressRight {
    width: 45px;
    display: flex;

    align-items: center;
  }
  .right {
    width: 20px;
    height: 20px;
  }
}
.van-card__num {
  color: #1abca9;
}
.van-card__price {
  color: #f04844;
  font-size: 12px;
}
.van-card__desc {
  color: #ccc;
}
</style>
